package j2025.j06;

import java.util.Stack;

/**
 * @Author 猫大仙
 */
public class j0607 {
    public boolean isValid(String s) {
        Stack<Character> stack = new Stack<>();
        for(char c : s.toCharArray()){
            if(c == '(' || c == '{' || c == '['){
                stack.push(c);
            }else {
                if(stack.isEmpty()){
                    return false;
                }else {
                    char left = stack.peek();
                    if(left=='('&&c==')' || left=='{'&&c=='}' || left=='['&&c==']'){
                        stack.pop();
                    }else {
                        return false;
                    }
                }
            }
        }
        return stack.isEmpty();
    }
}
